<?php
class scaffolding
    {


    /*public $xmlDatabase;
 public $formClass = "snapol_form";
 
 public $tablePaging = 20;

 public $errorClass = "snapol_error_message";



 public $xmlFilename;
 public $baseDir = false;   */

    public $tableName;
    public $tableId;
    public $usergroup = 10;

    public $tableUrl;
    public $formUrl;
    public $detailUrl;

    public $newItem = true;

    public $tableClass = "snapol_table";
    public $htmlFormId;

    
    public $scaffoldingTable = "";
    
    private $tableData;

    public $formTitle = "";

    function createBackendAdministration()
        {

        require_once(config::$basePath . "/system/api/simplehtmldom/simple_html_dom.php");

        $this->tableData=db::getDataLine("_table", "table_name='{$this->tableName}'");

        $this->tableUrl="/admin" . convert::convertToUrl($this->tableName);
        $this->formUrl="/admin/neu" . convert::convertToUrl($this->tableName);
        $this->detailUrl="/admin/detail" . convert::convertToUrl($this->tableName);


        // speichern der Url's
        $tableId=db::getValue("SELECT id FROM _table WHERE table_name='{$this->tableName}'");
        $data=array();
        $data['table_url']=$this->tableUrl;
        $data['form_url']=$this->formUrl;
        $data['detail_url']=$this->detailUrl;
        db::saveData("_table", $data, $tableId);


        // echo $this->tableData['table_caption'];
        // exit;


        // Formular erstellen
        $htmlForm=$this->createForm();

        // Form erstellen
        $content=new content();
        $content->title="Neuer Eintrag ({$this->tableData['table_caption']})";
        $content->url=$this->formUrl;
        $content->menuActive=0;
        $content->template="admin.html";
        $content->usergroup=$this->usergroup;
        $content->usergroupEdit=99;
        $content->parentUrl=$this->tableUrl;
        $content->text=$htmlForm;
        $content->systemPath="/";
        $content->createContentFile=false;


        // falls Content Update
        if (db::getCount("content", "_url='{$this->formUrl}'") > 0)
            {
            $content->contentId=db::getId("content", "_url='{$this->formUrl}'");
            }
        //echo "id=".$content->contentId;

        $content->createContent();


        // Tabelle erstellen

        $htmlTable=$this->createTable();

        // Tabelle erstellen
        $content=new content();
        $content->title=$this->tableData['table_caption'];
        $content->url=$this->tableUrl;
        $content->menuActive=1;
        $content->template="admin.html";
        $content->usergroup=$this->usergroup;
        $content->usergroupEdit=99;
        $content->parentUrl="/admin";
        $content->text=$htmlTable;
        $content->systemPath="/";
        $content->createContentFile=false;

        // falls Content Update
        if (db::getCount("content", "_url='{$this->tableUrl}'") > 0)
            {
            $content->contentId=db::getId("content", "_url='{$this->tableUrl}'");
            }


        //echo "id=".$content->contentId;

        $content->createContent();


        // Detail View erstellen
        $htmlDetail=$this->createDetail();
        $content=new content();
        $content->title="Detail" . $this->tableData['table_caption'];
        $content->url=$this->detailUrl;
        $content->menuActive=0;
        $content->template="admin.html";
        $content->usergroup=$this->usergroup;
        $content->usergroupEdit=99;
        $content->parentUrl=$this->tableUrl;
        $content->text=$htmlDetail;
        $content->systemPath="/";
        $content->createContentFile=false;

        if (db::getCount("content", "_url='{$this->detailUrl}'") > 0)
            {
            $content->contentId=db::getId("content", "_url='{$this->detailUrl}'");
            }

        $content->createContent();
        }


    /**
    * erstellen eines Html Formular
    * 
    */
    function createForm()
        {

            
        $this->tableData=db::getDataLine("_table", "table_name='{$this->tableName}'");
            
        //echo "tabelle: $table <br>";

        $htmlForm="";
        $searchIndexModus=false;
        $tableUrl="";

        // Xml Datenbank einlesen
        /*if ($this->xmlDatabase == NULL)
            {
            $this->xmlDatabase=new xml_database();
            $this->xmlDatabase->baseDir=$this->baseDir;
            $this->xmlDatabase->xmlFilename=$this->xmlFilename;

            $this->xmlDatabase->readXmlFile();
            }

        $xmlTable=$this->xmlDatabase->getTable($table);*/


        // print_r($xmlTable);
        //foreach ($this->xmlDatabase->xmlTable as $table)
        //  {
        $counter=0;


        // scaffolding
        /*   if ($table->scaffolding)
               {
               $tableUrl        ="/admin" . convert::convertToUrl($table->tableName);
               $formUrl         ="/admin/neu" . convert::convertToUrl($table->tableName);

               $htmlForm        ='';
               //$tableArray = general::stringToArray()

               $searchIndexModus=false; */

        // foreach ($xmlTable->xmlField as $field)
        //   {


        // einlesen der html fiels
        foreach (db::getData("_field_type") as $fieldTypeData)
            {

            $filename = config::$basePath . "/system/scaffolding/{$fieldTypeData['field_type']}.php";

            if (file::fileExists($filename, false))
                {
                $itemHtml=file::readTextFile($filename, false);
                }
            else
                {
                echo "not found {$fieldTypeData['field_type']}";

/*    $itemHtml='<p><label>[caption] <span com="error" field="[name]" class="">Keine gÃƒÂ¼ltige Eingabe</span></label>
<input type="text" name="[name]" id="[name]" /></p>'; */
                }


            // falls Projekt spezifisches scaffolding
            $filename=config::$projectPath . "/scaffolding/{$fieldTypeData['field_type']}.php";

            if (file::fileExists($filename, true))
                {
                $itemHtml=file::readTextFile($filename, true);
                }

            $data=array();
            $data['html']=$itemHtml;
            db::saveData("_field_type", $data, $fieldTypeData['id']);


/*$filename = config::$projectPath . "/scaffolding/{$fieldTypeData['field_type']}.html";    
   if (file::fileExists($filename, false))
       {
       $itemHtml=file::readTextFile($filename, false);
       }
   else
       {

       $itemHtml='<p><label>[caption] <span com="error" field="[name]" class="">Keine gÃƒÂ¼ltige Eingabe</span></label>
<input type="text" name="[name]" id="[name]" /></p>';
       } */

            }

        $html="";

        $itemCounter=0;

        foreach (db::getData("_table_field,_table,_field_type", "table_name='{$this->tableName}'",
            "item_order") as $tableField)
            
        /*$sql = "SELECT `_html_form_field`.id _html_form_field_id,`_table_field`.id _table_field_id,`_field_type`.id _field_type_id,`_html_form_field`.*,`_table_field`.*,`_field_type`.* FROM `_html_form_field` JOIN `_table_field` ON (_table_field.id = _html_form_field.__table_field ) JOIN `_field_type` ON (_field_type.id = _table_field.__field_type ) WHERE __html_form='{$this->htmlFormId}' ORDER BY _html_form_field.item_order";
        foreach (db::getQuery($sql) as $tableField)            */
            {
            if ($tableField['form_visible'])
                {
                if ($tableField['search_index'])
                    {
                    $searchIndexModus=true;
                    }


                //print_r($tableField);
                $htmlItem=$tableField['html'];


                // Set Focus setzen (beim ersten Element und falls es Text Input ist)
                if ($itemCounter == 0)
                    {
                    //wieder aktivieren problem mit php und html header!!!!
                    $htmlItem=dom::setAttribute("input", "set_focus", "true", $htmlItem);
                    }
                $itemCounter++;


                //$itemHtml=dom::setAttribute("input", "name", $field->fieldName, $itemHtml);
                //$itemHtml=dom::setAttribute("input", "id", $field->fieldName, $itemHtml);
                $htmlItem=str_ireplace("[field_caption]", $tableField['field_caption'], $htmlItem);
                $htmlItem=str_ireplace("[field_name]", $tableField['field_name'], $htmlItem);
                $htmlItem=str_ireplace("[default_value]", $tableField['default_value'], $htmlItem);


                // falls join
                if ($tableField['field_type'] == "join")
                    {

                    $htmlItem=dom::setAttribute("select", "com", "db_select", $htmlItem);

                    $selectTable=substr($tableField['field_name'], 1);
                    $htmlItem=dom::setAttribute("select", "table", $selectTable, $htmlItem);

                    $mainField=db::getValue("SELECT main_field FROM _table WHERE table_name='$selectTable'");

                    // $joinField=$tableField['main_field'];
                    //$joinField="";

                    if ($mainField == "")
                        {
                        $mainField=$selectTable;
                        }

                    $htmlItem=dom::setAttribute("select", "field", $mainField, $htmlItem);
                    $htmlItem=dom::setAttribute("select", "selected_value", $tableField['field_name'], $htmlItem);
                    $htmlItem=dom::setAttribute("select", "var", "viewformdata", $htmlItem);


                    //  com="data_select" table="[select_table]" field="[join_field]"
                    }


                // falls required
                if ($tableField['required'] == 1)
                    {

                    // $htmlItem = dom::setAttribute("input", "check_content", "true", $htmlItem);

                    switch ($tableField['field_type'])
                        {
                        case "email":
                            $htmlItem=dom::setAttribute("input", "check_email", "true", $htmlItem);
                            break;

                        case "url":
                            $htmlItem=dom::setAttribute("input", "check_url", "true", $htmlItem);
                            break;

                        case "number":
                            $htmlItem=dom::setAttribute("input", "check_number", "true", $htmlItem);
                            break;
                            
                        case "long_text":
                            $htmlItem=dom::setAttribute("textarea", "check_content", "true", $htmlItem);
                            break;
                            

                        default:
                            if ($tableField['field_name'] !== "login")
                                {
                                $htmlItem=dom::setAttribute("input", "check_content", "true", $htmlItem);
                                }
                        }


                    // falls Login
                    if ($tableField['field_name'] == "login")
                        {
                        $htmlItem=dom::setAttribute("input", "check_login", "true", $htmlItem);
                        }


                    // Error Message ersetzen
                    $errorMessage=trim($tableField['error_message']);

                    if ($errorMessage == "")
                        {
                        $errorMessage="Keine gültige Angabe.";
                        }

                    $htmlItem=str_ireplace("[error_message]", $errorMessage, $htmlItem);

                    $htmlItem=str_ireplace("[required_begin]", "", $htmlItem);
                    $htmlItem=str_ireplace("[required_end]", "", $htmlItem);
                    }
                else
                    {
                    // falls required nicht aktiviert ist
                    $htmlItem=re::regexReplace('\[required_begin\].*?\[required_end\]', $htmlItem, "");
                    }

                $html=$html . $htmlItem;
                }
            }


        /*  $htmlForm = '<form id="form1" name="form1" method="post" action="[action]" com="save_form" table="[table]">
          [form]
          
          <p>
     <input type="submit" name="button" id="button" value="Senden" />
   </p>
          
 </form>'; */

        $filename=config::$basePath . "/system/scaffolding/form.php";

        if (file::fileExists($filename, false))
            {
            $htmlForm=file::readTextFile($filename, false);
            }


        // falls Projekt spezifisches Form Scaffolding
        $filename=config::$projectPath . "/scaffolding/form.php";

        if (file::fileExists($filename, true))
            {
            $htmlForm=file::readTextFile($filename, true);
            }

        $mTable="";


        // nm Tabelle anfügen
        //foreach (db::getData("_table", "n_table='{$this->tableName}'") as $dataTable) {

        $this->tableId=db::getValue("SELECT id FROM _table WHERE table_name='{$this->tableName}'");
        $mFormTable="";

        foreach (db::getData("_nm_table", "n_table='{$this->tableId}'") as $dataTable)
            {

            //$mTable = db::getValue("SELECT table_name FROM _table WHERE id='{$dataTable['m_table']}'");
            $nTable = db::getValue("SELECT table_name FROM _table WHERE id='{$dataTable['n_table']}'");
            $mTable=$dataTable['m_table'];
            $mTableId=db::getValue("SELECT id FROM _table WHERE table_name='$mTable'");

            $htmlItem=file::readTextFile("/system/scaffolding/data_checkbox.php", true);

            //$htmlItem=str_ireplace("[title]", $dataTable['m_table'], $htmlItem);
            $title=db::getValue("SELECT table_caption FROM _table WHERE table_name='{$mTable}'");
            $htmlItem=str_ireplace("[title]", $title, $htmlItem);

            $htmlItem=str_ireplace("[n_table]", $nTable, $htmlItem);

            $htmlItem=str_ireplace("[m_table]", $mTable, $htmlItem);


            // erstes Feld auslesen
            if (db::fieldExist($mTable, $mTable))
                {

                // tabelle und feld sind identisch
                $mField=$mTable;
                }
            else
                {

                // erstes Feld ist main field
                $mField=db::getValue(
                    "SELECT field_name FROM _table_field WHERE __table='{$mTableId}' ORDER BY item_order LIMIT 1");
                }

            // wurde main_field definiert

            $htmlItem=str_ireplace("[m_field]", $mField, $htmlItem);

            $htmlItem=str_ireplace("[m_table]", $nTable . "_" . $mTable, $htmlItem);


            //m_table="gruppe,rubrik" nm_table="true"
            //$mFormTable = re::getAttributeValue("")
            if ($mFormTable !== "")
                {
                $mFormTable=$mFormTable . ",";
                }
            $mFormTable=$mFormTable . $mTable; //['m_table'];

            $htmlForm=dom::setAttribute("form", "n_table", $nTable, $htmlForm);
            $htmlForm=dom::setAttribute("form", "m_table", $mFormTable, $htmlForm);

            $htmlForm=dom::setAttribute("form", "nm_table", "true", $htmlForm);

            $html=$html . $htmlItem;
            }

        $htmlForm=str_ireplace("[form]", $html, $htmlForm);
        $htmlForm=str_ireplace("[table_name]", $this->tableName, $htmlForm);
        //     $htmlForm=str_ireplace("[table_caption]", $this->tableCName, $htmlForm);
        $htmlForm=str_ireplace("[action]", $this->tableUrl, $htmlForm);
        
        
        //$htmlForm=str_ireplace("[form_title]", $this->formTitle, $htmlForm);

        $formTitle = '<?php if (isset($_REQUEST["id"])) {
            echo "'.$this->tableData['form_title_update'].'";
        } else {
            echo "'.$this->tableData['form_title_insert'].'";
        } ?>';

        
        

        $htmlForm=str_ireplace("[form_title]", $formTitle, $htmlForm);


        
        
        
        // falls Search Index
        if ($searchIndexModus)
            {
            $htmlForm=dom::setAttribute("form", "search_index", "true", $htmlForm);
            }


        // falls Url Table
        if ($this->tableData['url_table'])
            {
            $htmlForm=dom::setAttribute("form", "url_field", $this->tableData['url_field'], $htmlForm);
            $htmlForm=dom::setAttribute("form", "pre_url", $this->tableData['pre_url'], $htmlForm);
            }


        // Property Modus deaktivieren
        $dom=str_get_html($htmlForm);
        $domArray=$dom->find("[com]");

        foreach ($domArray as $item)
            {
            $item->property_modus="false";
            }

        $htmlForm=$dom->save();


        //echo $htmlForm;
        //exit;

        return $htmlForm;


        //exit;

        // falls required_text, Fehlermeldung einbinden
        //         $fieldTitle = $field->fieldCaption;


        // $html = $html.$fieldTitle;


        // falls required_text, Fehlermeldung einbinden
        /*        $fieldTitle = $field->fieldCaption;
    
                if ($field->required)
                    {
                    $fieldTitle=$fieldTitle . " <b>[error:" . strtolower($field->fieldName) . "]</b>";
                    }
    
                if ($field->searchIndex)
                    {
                    $searchIndexModus=true;
                    }
    
    
                // Text Component
                if (($field->fieldType == "text") or ($field->fieldType == "time"))
                    {
                    
                        
                    $filename = config::$projectPath . "/scaffolding/text_input.html";    
                    if (file::fileExists($filename, false))
                        {
    
                        $itemHtml=file::readTextFile($filename, false);
                        }
                    else
                        {
     
                        $itemHtml='<p><label>[caption] <span com="error" field="[name]" class="">Keine gÃƒÂ¼ltige Eingabe</span></label>
      <input type="text" name="[name]" id="[name]" /></p>';
                        }
    
      
                        
                    //$itemHtml=dom::setAttribute("input", "name", $field->fieldName, $itemHtml);
                    //$itemHtml=dom::setAttribute("input", "id", $field->fieldName, $itemHtml);
                    $itemHtml=str_ireplace("[caption]", $field->fieldCaption, $itemHtml);
                    $itemHtml=str_ireplace("[name]", $field->fieldName, $itemHtml);
                    
                 
                    
    
                    if ($field->required)
                        {    
                            $itemHtml=dom::setAttribute("input", "check_content", "true", $itemHtml);   
                        }
                    
                    
                    
                    // falls required_text, Fehlermeldung einbinden
                   /* $check="";
                    $fieldTitle=$field->fieldCaption;
    
                    if ($field->required)
                        {
                        $check='check_content="true"';
                        $fieldTitle=$field->fieldCaption . ' <span com="error" field="' . $field->fieldName . '" class="'
                            . $this->errorClass . '">Keine gÃƒÂ¼ltige Eingabe</span>';
                        }
    
                    $text='<p><label>' . $fieldTitle . '</label>
      <input type="text" name="' . $field->fieldName . '" id="' . $field->fieldName . '" ' . $check . ' /></p>';*/

        /*             $text = $itemHtml;
                     
                     
                     
                     
                     
                     }
     
                 // eMail Component
                 if ($field->fieldType == "email")
                     {
     
     
                     // falls required_text, Fehlermeldung einbinden
                     $check="";
                     $fieldTitle=$field->fieldCaption;
     
                     if ($field->required)
                         {
                         $check='check_email="true"';
                         $fieldTitle=$field->fieldCaption . ' <span com="error" field="' . $field->fieldName . '" class="'
                             . $this->errorClass . '">Keine gÃƒÂ¼ltige eMail Adresse</span>';
                         }
     
                     $text='<p><label>' . $fieldTitle . '</label>
       <input type="text" name="' . $field->fieldName . '" id="' . $field->fieldName . '" ' . $check . ' /></p>';
                     }
     
                 // Url Component
                 if ($field->fieldType == "url")
                     {
     
     
                     // falls required_text, Fehlermeldung einbinden
                     $check="";
     
                     if ($field->required)
                         {
                         $check='check_url="true"';
                         $fieldTitle=$field->fieldCaption . ' <span com="error" field="' . $field->fieldName . '" class="'
                             . $this->errorClass . '">Keine gÃƒÂ¼ltige Url</span>';
                         }
     
                     $text='<p><label>' . $fieldTitle . '</label>
       <input type="text" name="' . $field->fieldName . '" id="' . $field->fieldName . '" ' . $check . ' /></p>';
                     }
     
                 // Number Component
                 if ($field->fieldType == "number")
                     {
     
     
                     // falls required_text, Fehlermeldung einbinden
                     $check="";
     
                     if ($field->required)
                         {
                         $check='check_number="true"';
                         $fieldTitle=$field->fieldCaption . ' <span com="error" field="' . $field->fieldName . '" class="'
                             . $this->errorClass . '">Keine gÃƒÂ¼ltige Zahl</span>';
                         }
     
                     $text='<p><label>' . $fieldTitle . '</label>
       <input type="text" name="' . $field->fieldName . '" id="' . $field->fieldName . '" ' . $check . ' /></p>';
                     }
     
     
                 // Rational Component
                 if ($field->fieldType == "rational_number")
                     {
     
     
                     // falls required_text, Fehlermeldung einbinden
                     $check="";
     
                     if ($field->required)
                         {
                         $check='check_number="true"';
                         $fieldTitle=$field->fieldCaption . ' <span com="error" field="' . $field->fieldName . '" class="'
                             . $this->errorClass . '">Keine gÃƒÂ¼ltige Zahl</span>';
                         }
     
                     $text='<p><label>' . $fieldTitle . '</label>
       <input type="text" name="' . $field->fieldName . '" id="' . $field->fieldName . '" ' . $check . ' /></p>';
                     }
     
     
                 // Text Area Component
                 if ($field->fieldType == "long_text")
                     {
     
     
                     // falls required_text, Fehlermeldung einbinden
                     $check="";
     
                     if ($field->required)
                         {
                         $check='check_content="true"';
                         $fieldTitle=$field->fieldCaption . ' <span com="error" field="' . $field->fieldName . '" class="'
                             . $this->errorClass . '">Fehlende Eingabe</span>';
                         }
     
                     $text='<p><label>' . $fieldTitle . '</label>
       <textarea name="' . $field->fieldName . '" id="' . $field->fieldName . '" ' . $check
                         . ' cols="60" rows="10"></textarea></p>';
                     }
     
     
                 // falls Text Area
                 if ($field->fieldType == "html")
                     {
                     $check="";
     
                     if ($field->required)
                         {
                         $check='check_content="true"';
                         $fieldTitle=$field->fieldCaption . ' <span com="error" field="' . $field->fieldName . '" class="'
                             . $this->errorClass . '">Fehlende Eingabe</span>';
                         }
     
                     $text='<p><label>' . $fieldTitle . '</label>
       <textarea com="ck_editor" name="' . $field->fieldName . '" id="' . $field->fieldName . '" ' . $check
                         . ' cols="60" rows="10"></textarea></p>';
                     }
     
     
                 // falls Datum
                 if ($field->fieldType == "date")
                     {
     
     
                     // falls required_text, Fehlermeldung einbinden
                     $check="";
     
                     if ($field->required)
                         {
                         $check='check_content="true"';
                         }
     
                     $text='<p><label>' . $fieldTitle . '</label>
       <input type="text" date_picker="true" name="' . $field->fieldName . '" id="' . $field->fieldName . '" ' . $check
                         . ' /></p>';
                     }
     
     
                 // falls Checkbox
                 if ($field->fieldType == "checkbox")
                     {
                     $text='<p>
       <label><input type="checkbox" name="' . $field->fieldName . '" id="' . $field->fieldName . '"  />'
                         . $field->fieldCaption . '</label></p>';
                     }
     
     
                 // falls Image File
                 if ($field->fieldType == "image")
                     {
                     $text='<p><img src="[system.base_url]/code/upload/' . $xmlTable->tableName . '/100/[form_view:' . $field->fieldName . ']" /></p><p><label>' . $fieldTitle . '</label>
       <input type="file"  name="' . $field->fieldName . '" id="' . $field->fieldName . '" /></p>';
                     }
     
     
                 // falls File
                 if ($field->fieldType == "file")
                     {
                     if ($field->required)
                         {
                         $check='check_content="true"';
                         $fieldTitle=$field->fieldCaption . ' <span com="error" field="' . $field->fieldName . '" class="'
                             . $this->errorClass . '">Keine Datei angegeben</span>';
                         }
     
                     $text='<p><label>' . $fieldTitle . '</label>
       <input type="file"  name="' . $field->fieldName . '" id="' . $field->fieldName . '" /></p>';
                     ;
                     }
     
     
                 // falls Select
                 if ($field->fieldType == "join")
                     {
                     
                         
                         
                         
                         
                         
                         
                     $filename = config::$projectPath . "/scaffolding/select.html";    
                     if (file::fileExists($filename, false))
                         {
     
                         $itemHtml=file::readTextFile($filename, false);
                         }
                     else
                         {
      
                         /*$itemHtml='<p><label>[caption] <span com="error" field="[name]" class="">Keine gÃƒÂ¼ltige Eingabe</span></label>
       <input type="text" name="" id="" /></p>';*/


        /*                 $itemHtml='<label>[caption]</label>       
                             <select name="[name]" id="[name]" com="data_select" table="[select_table]" field="[join_field]">
                             </select>';
       
                         }    
                         
                         
                         $selectTable=$field->fieldName;
                     $selectTable=substr($selectTable, 1);
     
     
                     //$joinTable=substr($value, 1);
                     $joinTable=substr($field->fieldName, 1);
     
                     $optionField="";
                     //if ($this->joinField !== "") {
     
                     foreach (general::stringToArray($field->joinField) as $joinFieldItem)
                         {
                         $optionField=$optionField . "[$joinFieldItem] ";
     
                         //echo "item=$joinFieldItem***";
                         }
     
     
                     // falls nichts definiert wurde
                     if ($optionField === "")
                         {
                         $optionField="[$selectTable]";
                         }
                         
                         
                         
                         
                         
                         $itemHtml=str_ireplace("[caption]", $fieldTitle=$field->fieldCaption, $itemHtml);
                     $itemHtml=str_ireplace("[name]", $fieldTitle=$field->fieldName, $itemHtml);
                      $itemHtml=str_ireplace("[select_table]", $selectTable, $itemHtml);  
                      $itemHtml=str_ireplace("[join_field]", $field->joinField, $itemHtml);  
     
     
     
                      
                      
                     if ($field->required)
                         {    
                             $itemHtml=dom::setAttribute("input", "check_content", "true", $itemHtml);   
                         }
                         
                         
                         
                         
                     
     
     /*$text='<label>' . $fieldTitle . '</label>
     <select name="' . $field->fieldName . '" id="' . $field->fieldName . '" com="data" table="' . $selectTable . '" orderby="" limit="">
     <option value="[id]">' . $optionField . '</option>
     </select>';*/

        /*      $text='<label>' . $fieldTitle . '</label>       
                      <select name="' . $field->fieldName . '" id="' . $field->fieldName . '" com="data_select" table="' . $selectTable . '" field="' . $field->joinField . '">
                      </select>'; */


        //                   $text = $itemHtml;

        //  echo $text;
        //  exit;


        //         }


        // falls required_text, Fehlermeldung einbinden
        /*if ($field->required)
            {
            $title=$title . " <b>[error:$field]</b>";
            }

        //$text=dom::replaceInnerHtml("label", $title, $text);

        //print_r($comData);
        //exit;

        //if ($com == "required_text")
        /* wieder aktivieren     if ($com == "text") // and ($comData['required'] == 1))
                 {
 
                 //$text = dom::replaceInnerHtml("label", $dataForm->data['field']." [error:{$dataForm->data['field']}]",$text);
                 $text=dom::replaceInnerHtml("label",
                                             $title . ' <span com="error" field="' . $value
                                                 . '" error_message="uups, es gab einen Fehler!!!">Error Message</span>',
                                             $text);
                 $text=dom::setAttribute("input", "check_content", "on", $text);
                 $text=dom::setAttribute("input", "check_content_error_message", "uups, hier gabs einen fehler.", $text);
                 }
 
             // falls required_email
             //if ($com == "required_email")
             if (($com == "email") and ($comData['required'] == 1))    
                 {
                 $text=dom::replaceInnerHtml("label",
                                             $title . ' <span com="error" field="' . $value
                                                 . '" error_message="Keine gÃƒÆ’Ã†â€™Ãƒâ€ Ã¢â‚¬â„¢ÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â¼ltige eMail Adresse.">Error Message</span>',
                                             $text);
                 $text=dom::setAttribute("input", "check_email", "on", $text);
                 }  */


        // Set Focus setzen (beim ersten Element)
        /*         if ($counter == 0)
                     {
     
     
                     //wieder aktivieren problem mit php und html header!!!!
                     $text=dom::setAttribute("input", "set_focus", "true", $text);
                     }
     
     
                 //echo $text;
     
                 $htmlForm=$htmlForm . $text;
     
                 $counter++;
                 //   } while ($dataForm->nextRow());
                 }
     
             //$text=component::getCom("input_submit");
             //$text = $replaceCom->getComData("input_submit");
             //$comData = $replaceCom->getComData("input_submit");
     
             // Submit Button anfÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¼gen
             //$comData=component::getCom("input_submit");
     
             //$text=$comData['body'];
     
             /*$text                     ='<p><label></label>  
     <input type="submit" name="" value="Speichern" /></p>'; */

        /*       $searchIndex="";
       
               if ($searchIndexModus)
                   {
                   $searchIndex=' search_index="true"';
                   }
       
               $urlTable="";
       
               if ($xmlTable->urlTable)
                   {
       
                   $urlTable=' url_table="true" url_field="' . $table->urlField . '"';
                   }
       
               $htmlForm='<form class="' . $this->formClass . '" action="' . $this->tableUrl . '" com="save_form" table="'
                   . $xmlTable->tableName . '"' . $searchIndex . $urlTable . ' update_id="[get:id]">' . $htmlForm;
       
               $htmlForm=$htmlForm . '<p><label></label>  
         <input type="submit" name="" value="Speichern" /></p></form>';   */

        //  return $htmlForm;

        }


    /**
    * erstellen einer Html Tabelle
    * 
    */
    function createTable()
        {

        $this->tableData=db::getDataLine("_table", "table_name='{$this->tableName}'");
        $scaffoldingTable=$this->tableName;


        // falls Projekt spezifisches Form Scaffolding
        //$filename = config::$projectPath . "/scaffolding/form.html";
        $filename=config::$basePath . "/system/scaffolding/table.php";

        if (file::fileExists($filename, false))
            {
            $htmlTable=file::readTextFile($filename, false);
            }


        // falls Projekt spezifisches Form Scaffolding
        $filename=config::$projectPath . "/scaffolding/table.php";

        if (file::fileExists($filename, true))
            {
            $htmlTable=file::readTextFile($filename, true);
            }


        // einfügen von Multi Upload
        if (($this->tableData['file_table']) or ($this->tableData['image_file_table']))
            {

            $filename=config::$basePath . "/system/scaffolding/multi_upload.php";

            if (file::fileExists($filename, false))
                {
                $htmlMultiUpload=file::readTextFile($filename, false);
                }

            $htmlTable=$htmlMultiUpload . $htmlTable;
            }


        // CSV Import


        //    echo $htmlTable;
        //    exit;


        //$htmlTable = str_ireplace("[form]", $html, $htmlTable);
        //$htmlTable=str_ireplace("[table_name]", $this->tableData['table_name'], $htmlTable);
        $htmlTable=str_ireplace("[table_caption]", $this->tableData['table_caption'], $htmlTable);
        $htmlTable=str_ireplace("[form_url]", $this->formUrl, $htmlTable);
        $htmlTable=str_ireplace("[table_url]", $this->tableUrl, $htmlTable);
        $htmlTable=str_ireplace("[detail_url]", $this->detailUrl, $htmlTable);


        //$htmlTable = str_ireplace("[table_caption]", $this->tableName, $htmlTable);


        //$htmlTable = str_ireplace("[action]", $this->tableUrl, $htmlTable);

        $htmlHeaderOrginal=re::getRegex("(\[header_begin\].*?\[header_end\])", $htmlTable);
        $htmlBodyOrginal=re::getRegex("(\[body_begin\].*?\[body_end\])", $htmlTable);

        $htmlHeader=re::getRegex("\[header_begin\](.*?)\[header_end\]", $htmlTable);
        $htmlBody=re::getRegex("\[body_begin\](.*?)\[body_end\]", $htmlTable);

        $header="";
        $body="";

        foreach (db::getData("_table_field,_table,_field_type", "table_name='{$this->tableName}'",
            "item_order") as $tableField)
            {
            if ($tableField['table_visible'])
                {

                $htmlHeaderTmp=$htmlHeader;
                $htmlBodyTmp=$htmlBody;

                //$htmlHeaderTmp=str_ireplace("[table_name]", $this->tableData['table_name'], $htmlHeaderTmp);
                $htmlHeaderTmp=str_ireplace("[table_caption]", $this->tableData['table_caption'], $htmlHeaderTmp);

                //$htmlBodyTmp=str_ireplace("[table_name]", $this->tableData['table_name'], $htmlBodyTmp);
                $htmlBodyTmp=str_ireplace("[table_caption]", $this->tableData['table_caption'], $htmlBodyTmp);

                $htmlHeaderTmp=str_ireplace("[field_name]", $tableField['field_name'], $htmlHeaderTmp);
                $htmlHeaderTmp=str_ireplace("[field_caption]", $tableField['field_caption'], $htmlHeaderTmp);

                $htmlBodyTmp=str_ireplace("[field_name]", $tableField['field_name'], $htmlBodyTmp);
                $htmlBodyTmp=str_ireplace("[field_caption]", $tableField['field_caption'], $htmlBodyTmp);


                // falls es angezeigt werden soll
                //    if ($tableField['table_visible'])
                //      {

                //$headerField=$value;  //$fieldTitle[$n];
                //$headerField=$tableField['field_caption'];
                $bodyField="[" . $tableField['field_name'] . "]";

                // falls Feld ein Search Index hat
                if ($tableField['search_index'])
                    {
                    $bodyField="[" . $tableField['field_name'] . ":bold]";
                    }

                if ($tableField['field_type'] == "image")
                    {
                    $headerField="&nbsp;";
                    $bodyField='<div align="center"><img src="[' . $tableField['field_name'] . ':100]" /></div>';
                    }

                if ($tableField['field_type'] == "file")
                    {
                    $bodyField='<a href="[' . $tableField['field_name'] . ']" target="_blank">['
                        . $tableField['field_name'] . ':filename]</a>';
                    }

                if ($tableField['field_type'] == "email")
                    {
                    $bodyField='<a href="mailto:[' . $tableField['field_name'] . ']">[' . $tableField['field_name']
                        . ']</a>';
                    }

                if ($tableField['field_type'] == "number")
                    {
                    $bodyField="[" . $tableField['field_name'] . ":number]";
                    }

                // Price Field
                if ($tableField['field_type'] == "price")
                    {
                    $bodyField="[" . $tableField['field_name'] . ":number] CHF";
                    }

                    
                    // Currency CHF
                if ($tableField['field_type'] == "currency_chf")
                    {
                    $bodyField="[" . $tableField['field_name'] . ":number] CHF";
                    }
                    
                    
                     // Currency EUR
                if ($tableField['field_type'] == "currency_eur")
                    {
                    $bodyField="[" . $tableField['field_name'] . ":number] EUR";
                    }
                    
                     // Currency USD
                if ($tableField['field_type'] == "currency_usd")
                    {
                    $bodyField="[" . $tableField['field_name'] . ":number] USD";
                    }
                    
                    
                /*if ($tableField['field_type'] == "year")
                    {
                    $bodyField="[" . $tableField['field_name'] . "]";
                    }*/

                // Url Field
                if ($tableField['field_type'] == "url")
                    { //[system.base_url] darf nich vorangestellt werden, da auch externe Links möglich
                    $bodyField='<a href="[' . $tableField['field_name'] . ']" target="_blank">['
                        . $tableField['field_name'] . ']</a>';
                    }

                // Date Field
                if ($tableField['field_type'] == "date")
                    {
                    $bodyField="[" . $tableField['field_name'] . ":short_date]";
                    }


                // Street/Number Field
                if ($tableField['field_type'] == "street_number")
                    {
                    $bodyField="[" . $tableField['field_name'] . "] [" . $tableField['field_name'] . "_number]";
                    }

                // Postal Code/City Field
                if ($tableField['field_type'] == "postal_code_city")
                    {
                    $bodyField="[" . $tableField['field_name'] . "_postal_code] [" . $tableField['field_name'] . "]";
                    }

                // Join Field
                if ($tableField['field_type'] == "join")
                    {
                    //$headerField=$joinTable;
                    // $headerField=$field->fieldCaption;

                    $joinTable=substr($tableField['field_name'], 1);
                    $mainField=db::getValue("SELECT main_field FROM _table WHERE table_name='{$joinTable}'");


                    //echo "SELECT main_field FROM _table WHERE table_name='{$joinTable}'";


                    // $joinField=$tableField['main_field'];
                    //$joinField="";

                    /*    if ($mainField == "")
                            {
                            //$mainField=$selectTable;
                            
                           
                        $bodyField="[$joinTable]";
                            
                            } */

                    $scaffoldingTable=$scaffoldingTable . "," . $joinTable;


                    //if ($tableField['join_field'] !== "")
                    if ($mainField !== "")
                        {

                        $bodyField="";

                        //foreach (general::stringToArray($tableField['join_field']) as $joinFieldItem)
                        foreach (general::stringToArray($mainField) as $joinFieldItem)
                            {
                            //$optionField=$optionField . "[$joinFieldItem] ";
                            $bodyField=$bodyField . "[$joinFieldItem] ";
                            }
                        }
                    else
                        {

                        //$joinField=$tableField['join_field'];
                        $bodyField="[$joinTable]";
                        }


                    //    echo $bodyField;
                    //  exit;


                    //$bodyField="[" . $joinTable . "]";

                    /*       $optionField="";
                           //if ($this->joinField !== "") {
       
                           foreach (general::stringToArray($field->joinField) as $joinFieldItem)
                               {
                               $optionField=$optionField . "[$joinFieldItem] ";
                               }
       
       
                           // falls nichts definiert wurde
                           if ($optionField === "")
                               {
                               $optionField="[" . substr($field->fieldName, 1) . "]";
                               }
       
                           $joinTable="$joinTable," . substr($field->fieldName, 1);
                           $bodyField=$optionField;*/
                    }

                $htmlBodyTmp=str_ireplace("[field]", $bodyField, $htmlBodyTmp);

                $header=$header . $htmlHeaderTmp;
                $body=$body . $htmlBodyTmp;


                /*         if ($tableField['field_type'] == "join")
                             {
                             //$headerField=$joinTable;
                             $headerField=$field->fieldCaption;
         
                             //$bodyField="[" . $joinTable . "]";
         
                             $optionField="";
                             //if ($this->joinField !== "") {
         
                             foreach (general::stringToArray($field->joinField) as $joinFieldItem)
                                 {
                                 $optionField=$optionField . "[$joinFieldItem] ";
                                 }
         
         
                             // falls nichts definiert wurde
                             if ($optionField === "")
                                 {
                                 $optionField="[" . substr($field->fieldName, 1) . "]";
                                 }
         
                             $joinTable="$joinTable," . substr($field->fieldName, 1);
                             $bodyField=$optionField;
                             }   */


                //$header = $header . "<th>$value</th>";
                /* if ($headerField !== "")
                     {
                     $header=$header . "<th>$headerField</th>";
                     $body=$body . "<td>$bodyField</td>";
                     }  */


                //print_r($tableField);
                //$htmlItem = $tableField['html'];


                //$html = $html.$htmlItem;
                }
            }


        // nm Felder anfügen
        $tableId=db::getId("_table", "table_name='{$this->tableName}'");

        foreach (db::getData("_nm_table", "n_table='{$tableId}'") as $dataNmTable)
            {

            $htmlHeaderTmp = $htmlHeader;
            $htmlBodyTmp=$htmlBody;

            //$htmlHeaderTmp=str_ireplace("[field_name]", $tableField['field_name'], $htmlHeaderTmp);
            $htmlHeaderTmp=str_ireplace("[field_caption]", $dataNmTable['m_table'], $htmlHeaderTmp);


            //, "'.$dataNmTable['m_table'].'"

            $bodyField="[{$dataNmTable['m_table']}:nm_list]";
            $htmlBodyTmp=str_ireplace("[field]", $bodyField, $htmlBodyTmp);

            $header=$header . $htmlHeaderTmp;
            $body=$body . $htmlBodyTmp;
            }

        $htmlTable=str_ireplace($htmlHeaderOrginal, $header, $htmlTable);
        $htmlTable=str_ireplace($htmlBodyOrginal, $body, $htmlTable);

        $htmlTable=str_ireplace("[table_name]", $scaffoldingTable, $htmlTable);
        $htmlTable=str_ireplace("[main_table_name]", $this->tableName, $htmlTable);


        // Where
        $htmlTable=str_ireplace("[table_where]", $this->tableData['table_where'], $htmlTable);


        // Order By
        $htmlTable=str_ireplace("[table_orderby]", $this->tableData['table_orderby'], $htmlTable);


        // main_field
        $htmlTable=str_ireplace("[main_field_caption]", $this->tableData['main_field_caption'], $htmlTable);
        $tmp="";

        $mainFieldOrderbyUp="";
        $mainFieldOrderbyDown="";

        foreach (general::stringToArray($this->tableData['main_field']) as $mainField)
            {
            $tmp = $tmp . "[" . $mainField . "] ";

            if ($mainFieldOrderbyUp !== "")
                {
                $mainFieldOrderbyUp=$mainFieldOrderbyUp . ",";
                }

            if ($mainFieldOrderbyDown !== "")
                {
                $mainFieldOrderbyDown=$mainFieldOrderbyDown . ",";
                }

            $mainFieldOrderbyUp=$mainFieldOrderbyUp . $mainField;
            $mainFieldOrderbyDown=$mainFieldOrderbyDown . $mainField . " desc";
            }
        $htmlTable=str_ireplace("[main_field]", $tmp, $htmlTable);

        $htmlTable=str_ireplace("[main_field_orderby_up]", $mainFieldOrderbyUp, $htmlTable);
        $htmlTable=str_ireplace("[main_field_orderby_down]", $mainFieldOrderbyDown, $htmlTable);


        // Search Form
        if ($this->tableData['search_form'])
            {

            $htmlTable=str_ireplace("[search_form_begin]", "", $htmlTable);
            $htmlTable=str_ireplace("[search_form_end]", "", $htmlTable);
            }
        else
            {

            //   echo $htmlTable;
            //   echo "****************************";

            $htmlTable=re::regexReplace("\[search_form_begin\].*?\[search_form_end\]", $htmlTable, "");
            //echo re::getRegex("(\[search_form_begin\].*?\[search_form_end\])", $htmlTable);

            //echo $htmlTable;

            // exit;
            }


        //    if ($this->editItem)
        //      {
        /*   $header=$header . "<th>&nbsp;</th>";
           //$body  =$body . "<td>" . $this->addDetailView() . "</td>";                    //this->tableArray[0]
           $body=$body . '<td><a href="[system.base_url]' . $this->formUrl . '?id=[' . $this->tableName
               . '_id]">editieren</a></td>';
           //    }                                       //[base_url]
   
           // if ($this->deleteItem)
           //   {
           $header=$header . "<th>&nbsp;</th>";
           $body=$body . '<td><a href="" click="delete_data" table="' . $this->tableName . '" id="['
               . $this->tableName . '_id]">lÃ¶schen</a></td>';  */
        // }

        // Search Field
        $searchProperty="";

        /*     if ($xmlTable->searchForm)
                {
                $searchProperty="[get:q]";
                }
    
            if ($xmlTable->sortableTable)
                {
                $component="data_sortable";
                }
            else
                {
                $component="data";
                }  */

        $orderby="";
        $paging="";
        $joinTable="";

        /*$htmlTable='<table class="' . $this->tableClass . '"><thead><tr>' . $header
            . '</tr></thead><tbody id="admin_table" com="data" table="' . $this->tableName
            . $joinTable . '" where="" orderby="' . $orderby . '" search="' . $searchProperty
            . '" paging="' . $paging . '">'; */


        /*       if ($this->tableData['sortable_table'])
                   {
                   $htmlTable=$htmlTable . '<tr id="[id]">';
                   }
               else
                   {
                   $htmlTable=$htmlTable . '<tr>';
                   } 
       
               $htmlTable=$htmlTable . $body . '</tr></tbody></table>'; */


        // Paging anhÃƒÂ¤ngen (bei sortable soll es kein Paging geben)
        /*     if (!$xmlTable->sortableTable)
                 {
                 $htmlTable=$htmlTable . '<div com="paging" table="' . $xmlTable->tableName . '" paging="'
                     . $this->tablePaging . '" show_paging="true">Paging</div>';
                 }/*/


        // anzeigen
        /*  if ($this->tableData['search_form'])
              {
              $htmlTable='<form id="form1" name="form1" method="get" action="">
            <label for="q"></label>
            <input type="text" name="q" id="q" value="[get:q]" />
            <input type="submit" name="button" id="button" value="Search" />
          </form>'
                  . $htmlTable;
              }  */

        //if ($this->newItem)
        //  {                                                      //[base_url]
        /*$htmlTable='<p><a class="snapol_button" href="[system.base_url]' . $this->formUrl . '">Neuer Eintrag</a></p>'
            . $htmlTable;*/


        // Property Modus deaktivieren
        $dom=str_get_html($htmlTable);
        $domArray=$dom->find("[com]");

        foreach ($domArray as $item)
            {
            $item->property_modus="false";
            }

        $htmlTable=$dom->save();

        return $htmlTable;


        /*       $this->xmlDatabase=new xml_database();
      $this->xmlDatabase->baseDir=false;
      $this->xmlDatabase->readXmlPath(config::$projectPath . "/db");*/

        /*    if ($this->xmlDatabase == NULL)
                {
                $this->xmlDatabase=new xml_database();
                $this->xmlDatabase->baseDir=$this->baseDir;
                $this->xmlDatabase->xmlFilename=$this->xmlFilename;
    
                $this->xmlDatabase->readXmlFile();
                }
    
            $xmlTable=$this->xmlDatabase->getTable($table);
    
            $headerField="";
            $bodyField="";
    
            $header="";
            $body="";
    
            $joinTable="";
    
    
            /*if ($this->tableField == "")
                {
                $field=db::getSnapolTableFieldArray($this->table);
                }
            else
                {
                $field=general::stringToArray($tableField);
                }*/


        //$fieldTitle = general::stringToArray($this->tableFieldTitle);

        /*    $n=0;
    
            foreach ($xmlTable->xmlField as $field)
                {
    
                //$type = $this->tableFieldType[$field];
                //$title=$value;
    
    
                // falls es angezeigt werden soll
                if ($field->tableVisible)
                    {
    
    
                    //$headerField=$value;  //$fieldTitle[$n];
                    $headerField=$field->fieldCaption;
                    $bodyField="[" . $field->fieldName . "]";
    
                    // falls Feld ein Search Index hat
                    if ($field->searchIndex)
                        {
                        $bodyField="[" . $field->fieldName . ":bold]";
                        }
    
                    if ($field->fieldType == "image")
                        {
                        $headerField="&nbsp;";
                        $bodyField='<img src="[' . $field->fieldName . ':100]" />';
                        }
    
                    if ($field->fieldType == "file")
                        {
                        $bodyField='<a href="[' . $field->fieldName . ']" target="_blank">[' . $field->fieldName
                            . ':filename]</a>';
                        }
    
                    if ($field->fieldType == "email")
                        {
                        $bodyField='<a href="mailto:[' . $field->fieldName . ']">[' . $field->fieldName . ']</a>';
                        }
    
                    if ($field->fieldType == "number")
                        {
                        $bodyField="[" . $field->fieldName . ":number]";
                        }
    
                    if ($field->fieldType == "url")
                        {
                        $bodyField='<a href="[' . $field->fieldName . ']" target="_blank">[' . $field->fieldName . ']</a>';
                        }
    
                    if ($field->fieldType == "date")
                        {
                        $bodyField="[" . $field->fieldName . ":short_date]";
                        }
    
                    if ($field->fieldType == "join")
                        {
                        //$headerField=$joinTable;
                        $headerField=$field->fieldCaption;
    
                        //$bodyField="[" . $joinTable . "]";
    
                        $optionField="";
                        //if ($this->joinField !== "") {
    
                        foreach (general::stringToArray($field->joinField) as $joinFieldItem)
                            {
                            $optionField=$optionField . "[$joinFieldItem] ";
                            }
    
    
                        // falls nichts definiert wurde
                        if ($optionField === "")
                            {
                            $optionField="[" . substr($field->fieldName, 1) . "]";
                            }
    
                        $joinTable="$joinTable," . substr($field->fieldName, 1);
                        $bodyField=$optionField;
                        }
    
    
                    //$header = $header . "<th>$value</th>";
                    if ($headerField !== "")
                        {
                        $header=$header . "<th>$headerField</th>";
                        $body=$body . "<td>$bodyField</td>";
                        }
    
                    $n++;
                    }
                }
    
            //    if ($this->editItem)
            //      {
            $header=$header . "<th>&nbsp;</th>";
            //$body  =$body . "<td>" . $this->addDetailView() . "</td>";                    //this->tableArray[0]
            $body=$body . '<td><a href="[system.base_url]' . $this->formUrl . '?id=[' . $xmlTable->tableName
                . '_id]">editieren</a></td>';
            //    }                                       //[base_url]
    
            // if ($this->deleteItem)
            //   {
            $header=$header . "<th>&nbsp;</th>";
    //$body  =$body . "<td>" . $this->addDetele() . "</td>";                                   //$this->tableArray[0]
            $body=$body . '<td><a href="" click="delete_data" table="' . $xmlTable->tableName . '" id="['
                . $xmlTable->tableName . '_id]">lÃ¶schen</a></td>';
            // }
    
            // Search Field
            $searchProperty="";
    
            if ($xmlTable->searchForm)
                {
                $searchProperty="[get:q]";
                }
    
            if ($xmlTable->sortableTable)
                {
                $component="data_sortable";
                }
            else
                {
                $component="data";
                }
    
            $htmlTable='<table class="' . $this->tableClass . '"><thead><tr>' . $header
                . '</tr></thead><tbody id="admin_table" com="' . $component . '" table="' . $xmlTable->tableName
                . $joinTable . '" where="" orderby="' . $xmlTable->tableOrderby . '" search="' . $searchProperty
                . '" paging="' . $this->tablePaging . '">';
    
            if ($xmlTable->sortableTable)
                {
                $htmlTable=$htmlTable . '<tr id="[id]">';
                }
            else
                {
                $htmlTable=$htmlTable . '<tr>';
                }
    
            $htmlTable=$htmlTable . $body . '</tr></tbody></table>';
    
    
            // Paging anhÃƒÂ¤ngen (bei sortable soll es kein Paging geben)
            if (!$xmlTable->sortableTable)
                {
                $htmlTable=$htmlTable . '<div com="paging" table="' . $xmlTable->tableName . '" paging="'
                    . $this->tablePaging . '" show_paging="true">Paging</div>';
                }
    
    
            // anzeigen
            if ($xmlTable->searchForm)
                {
                $htmlTable='<form id="form1" name="form1" method="get" action="">
              <label for="q"></label>
              <input type="text" name="q" id="q" value="[get:q]" />
              <input type="submit" name="button" id="button" value="Search" />
            </form>'
                    . $htmlTable;
                }
    
            //if ($this->newItem)
            //  {                                                      //[base_url]
            $htmlTable='<p><a class="snapol_button" href="[system.base_url]' . $this->formUrl . '">Neuer Eintrag</a></p>'
                . $htmlTable;
    
            return $htmlTable;  */

        }

    function createDetail()
        {

        $this->tableData=db::getDataLine("_table", "table_name='{$this->tableName}'");
        $scaffoldingTable=$this->tableName;  

        
        // falls Projekt spezifisches Form Scaffolding
        //$filename = config::$projectPath . "/scaffolding/form.html";
        $filename=config::$basePath . "/system/scaffolding/detail.php";

        if (file::fileExists($filename, false))
            {
            $htmlDetail2=file::readTextFile($filename, false);
            }


        // falls Projekt spezifisches Form Scaffolding
        $filename=config::$projectPath . "/scaffolding/detail.php";

        if (file::fileExists($filename, true))
            {
            $htmlDetail2=file::readTextFile($filename, true);
            }


        //$htmlTable = str_ireplace("[form]", $html, $htmlTable);
        //$htmlTable=str_ireplace("[table_name]", $this->tableData['table_name'], $htmlTable);
        /*  $htmlTable=str_ireplace("[table_caption]", $this->tableData['table_caption'], $htmlTable);
          $htmlTable=str_ireplace("[form_url]", $this->formUrl, $htmlTable);
          $htmlTable=str_ireplace("[detail_url]", $this->detailUrl, $htmlTable);  */


        //$htmlTable = str_ireplace("[table_caption]", $this->tableName, $htmlTable);

        //$htmlDetail2=str_ireplace("[table_name]", $this->tableName, $htmlDetail2);

        $htmlDetail2=str_ireplace("[main_field_caption]", $this->tableData['main_field_caption'], $htmlDetail2);

        $mainFieldReplace="";

        foreach (general::stringToArray($this->tableData['main_field']) as $mainField)
            {
            $mainFieldReplace=$mainFieldReplace . "[" . $mainField . "] ";
            }

        $htmlDetail2=str_ireplace("[main_field]", $mainFieldReplace, $htmlDetail2);


        //$htmlTable = str_ireplace("[action]", $this->tableUrl, $htmlTable);

        $htmlDetailOrginal=re::getRegex("(\[detail_begin\].*?\[detail_end\])", $htmlDetail2);
        /*$htmlBodyOrginal=re::getRegex("(\[body_begin\].*?\[body_end\])", $htmlTable);

        $htmlHeader=re::getRegex("\[header_begin\](.*?)\[header_end\]", $htmlTable);
        $htmlBody=re::getRegex("\[body_begin\](.*?)\[body_end\]", $htmlTable);  */
        $htmlDetail=re::getRegex("\[detail_begin\](.*?)\[detail_end\]", $htmlDetail2);

        //$header="";
        //$body="";
        $detail="";

        foreach (db::getData("_table_field,_table,_field_type", "table_name='{$this->tableName}'", "item_order") as $tableField)
            {
            if ($tableField['detail_visible'])
                {

                $htmlDetailTmp=$htmlDetail;
                //$htmlBodyTmp=$htmlBody;

                //$htmlHeaderTmp=str_ireplace("[table_name]", $this->tableData['table_name'], $htmlHeaderTmp);
                $htmlDetailTmp=str_ireplace("[table_caption]", $this->tableData['table_caption'], $htmlDetailTmp);

                //$htmlBodyTmp=str_ireplace("[table_name]", $this->tableData['table_name'], $htmlBodyTmp);
                //$htmlBodyTmp=str_ireplace("[table_caption]", $this->tableData['table_caption'], $htmlBodyTmp);

                $htmlDetailTmp=str_ireplace("[field_name]", $tableField['field_name'], $htmlDetailTmp);
                $htmlDetailTmp=str_ireplace("[field_caption]", $tableField['field_caption'], $htmlDetailTmp);

                //$htmlBodyTmp=str_ireplace("[field_name]", $tableField['field_name'], $htmlBodyTmp);
                //$htmlBodyTmp=str_ireplace("[field_caption]", $tableField['field_caption'], $htmlBodyTmp);


                // falls es angezeigt werden soll
                //    if ($tableField['table_visible'])
                //      {

                //$headerField=$value;  //$fieldTitle[$n];
                //$headerField=$tableField['field_caption'];
                $bodyField="[" . $tableField['field_name'] . "]";

                // falls Feld ein Search Index hat
                if ($tableField['search_index'])
                    {
                    $bodyField="[" . $tableField['field_name'] . ":bold]";
                    }

                if ($tableField['field_type'] == "image")
                    {
                    $headerField="&nbsp;";
                    $bodyField='<img src="[' . $tableField['field_name'] . ':100]" />';
                    }

                if ($tableField['field_type'] == "file")
                    {
                    $bodyField='<a href="[' . $tableField['field_name'] . ']" target="_blank">['
                        . $tableField['field_name'] . ':filename]</a>';
                    }

                if ($tableField['field_type'] == "email")
                    {
                    $bodyField='<a href="mailto:[' . $tableField['field_name'] . ']">[' . $tableField['field_name']
                        . ']</a>';
                    }

                if ($tableField['field_type'] == "number")
                    {
                    $bodyField="[" . $tableField['field_name'] . ":number]";
                    }

                if ($tableField['field_type'] == "url")
                    {
                    $bodyField='<a href="[' . $tableField['field_name'] . ']" target="_blank">['
                        . $tableField['field_name'] . ']</a>';
                    }

                if ($tableField['field_type'] == "date")
                    {
                    $bodyField="[" . $tableField['field_name'] . ":short_date]";
                    }
                    
                    
                    
                     // Street/Number Field
                if ($tableField['field_type'] == "street_number")
                    {
                    $bodyField="[" . $tableField['field_name'] . "] [" . $tableField['field_name'] . "_number]";
                    }

                // Postal Code/City Field
                if ($tableField['field_type'] == "postal_code_city")
                    {
                    $bodyField="[" . $tableField['field_name'] . "_postal_code] [" . $tableField['field_name'] . "]";
                    }
                    
                    
                    
                    
                    

                if ($tableField['field_type'] == "join")
                    {
                    //$headerField=$joinTable;
                    // $headerField=$field->fieldCaption;

                    $joinTable=substr($tableField['field_name'], 1);
                    $scaffoldingTable=$scaffoldingTable . "," . $joinTable;   
                    $bodyField="[$joinTable]";

                    //$scaffoldingTable=$scaffoldingTable . "," . $joinTable;

                    if ($tableField['join_field'] !== "")
                        {

                        $bodyField="";

                        foreach (general::stringToArray($tableField['join_field']) as $joinFieldItem)
                            {
                            //$optionField=$optionField . "[$joinFieldItem] ";
                            $bodyField=$bodyField . "[$joinFieldItem] ";
                            }
                        }
                    else
                        {

                        $joinField=$tableField['join_field'];
                        }


                    //$bodyField="[" . $joinTable . "]";

                    /*       $optionField="";
                           //if ($this->joinField !== "") {
       
                           foreach (general::stringToArray($field->joinField) as $joinFieldItem)
                               {
                               $optionField=$optionField . "[$joinFieldItem] ";
                               }
       
       
                           // falls nichts definiert wurde
                           if ($optionField === "")
                               {
                               $optionField="[" . substr($field->fieldName, 1) . "]";
                               }
       
                           $joinTable="$joinTable," . substr($field->fieldName, 1);
                           $bodyField=$optionField;*/
                    }

                $htmlDetailTmp=str_ireplace("[field]", $bodyField, $htmlDetailTmp);

                //$header=$header . $htmlHeaderTmp;
                //$body=$body . $htmlBodyTmp;
                $detail=$detail . $htmlDetailTmp;


                /*         if ($tableField['field_type'] == "join")
                             {
                             //$headerField=$joinTable;
                             $headerField=$field->fieldCaption;
         
                             //$bodyField="[" . $joinTable . "]";
         
                             $optionField="";
                             //if ($this->joinField !== "") {
         
                             foreach (general::stringToArray($field->joinField) as $joinFieldItem)
                                 {
                                 $optionField=$optionField . "[$joinFieldItem] ";
                                 }
         
         
                             // falls nichts definiert wurde
                             if ($optionField === "")
                                 {
                                 $optionField="[" . substr($field->fieldName, 1) . "]";
                                 }
         
                             $joinTable="$joinTable," . substr($field->fieldName, 1);
                             $bodyField=$optionField;
                             }   */


                //$header = $header . "<th>$value</th>";
                /* if ($headerField !== "")
                     {
                     $header=$header . "<th>$headerField</th>";
                     $body=$body . "<td>$bodyField</td>";
                     }  */


                //print_r($tableField);
                //$htmlItem = $tableField['html'];


                //$html = $html.$htmlItem;
                }
            }

        //$htmlTable=str_ireplace($htmlHeaderOrginal, $header, $htmlTable);
        $htmlDetail2=str_ireplace($htmlDetailOrginal, $detail, $htmlDetail2);
        
        
        $htmlDetail2=str_ireplace("[table_name]", $scaffoldingTable, $htmlDetail2); 
        

        
        
        
        
        // Property Modus deaktivieren
        $dom=str_get_html($htmlDetail2);
        $domArray=$dom->find("[com]");

        foreach ($domArray as $item)
            {
            $item->property_modus="false";
            }

        $htmlDetail2=$dom->save();
        
        
        
        
        
        
        
        //$htmlTable=str_ireplace("[table_name]", $scaffoldingTable, $htmlTable);

        return $htmlDetail2;
        }


    /**
    * create a ul list
    * 
    */
    function createList()
        {

        $html='<ul com="data" table="' . $this->tableName . '"><li>[id]</li></ul>';

        return $html;
        }
    }
?>